package com.game.springbootstart.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.game.springbootstart.DTO.GamesDTO;
import com.game.springbootstart.entity.Games;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 游戏表 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-01-29
 */
@Mapper
public interface GamesMapper extends BaseMapper<Games> {
    @Select("select name from game.category where id in (select category_id from game.games) and status = 1")
    List<String> getCategories();

    @Select("select * from game.games where category_id = (select id from game.category where category.name=#{categoryName})")
    List<Games> selectCategoryByName(String categoryName);

    @Select("select * from game.games where status = '上线'")
    List<Games> listByStatus();

    @Select("select * from game.games where status = '上线' and name like CONCAT('%', #{keyword}, '%')")
    List<Games> searchGames(String keyword);

    @Select("select * from game.games where id = #{id}")
    Games listId(Long id);

    @Select("select id from game.games where name = #{name}")
    Long selectIdByName(String name);

    @Select("SELECT g.id, g.name, g.category_id, c.name AS category_name, g.description, " +
            "g.image_url, g.release_date, g.developer, g.platform, g.status, " +
            "g.create_time, g.update_time " +
            "FROM games g " +
            "LEFT JOIN category c ON g.category_id = c.id " +
            "WHERE g.name LIKE CONCAT('%', #{name}, '%')")
    IPage<GamesDTO> selectGamesWithCategory(Page<GamesDTO> page, String name);

    @Select("select name from games")
    List<String> selectGames();
}
